home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / flute.zip / SAMP_ACT.C / SAMP_ACT.C < prev    next >
C/C++ Source or Header  |  1995-04-07  |  6KB  |  177 lines

  1. /**************************************************************************** */
  2. /* Samp_Act.c */
  3. /* Sample Window Class used to illustrate Window Acts*/
  4. /* Search for WINDACTS to see the changes made*/
  5. /*****************************************************************************/
  6.  
  7. #include <windows.h>            /* required for all Windows applications */
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include "resource.h"
  11.  
  12. #include "windacts.h"        // WINDACTS
  13.  
  14. // variables used by the program
  15. char    sValue[256];    // the string displayed in the window
  16. long    lValue;            // the long value in the window
  17. HINSTANCE    hInst;        // handle of this instance
  18.  
  19. UINT    uActListMsg;    // WINDACTS - holds the id of message "ActList"
  20.  
  21. // Function prototypes
  22. long FAR PASCAL SampActWindProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  23.  
  24.  
  25.  
  26. /**************************************************************************/
  27. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  28. HANDLE hInstance;                 /* current instance         */
  29. HANDLE hPrevInstance;                 /* previous instance         */
  30. LPSTR lpCmdLine;                 /* command line             */
  31. int nCmdShow;                     /* show-window type (open/icon) */
  32. {
  33.     MSG msg;                     /* message                 */
  34.     WNDCLASS      wc;
  35.     HWND    hWnd;
  36.  
  37.     hInst = hInstance;
  38.  
  39.     // register the WindActs message used by all our window classes.
  40.     uActListMsg = RegisterWindowMessage("ActList");    // WINDACTS
  41.  
  42.     if (!hPrevInstance) {
  43.         /* text editor window */
  44.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  45.         wc.style = 0;      /* Class style(s).            */
  46.         wc.lpfnWndProc = SampActWindProc;     /* Function to retrieve messages for       */
  47.         wc.hIcon = LoadIcon(NULL,(LPCSTR)IDI_APPLICATION);
  48.         wc.cbClsExtra = 0;            /* No per-class extra data.          */
  49.         wc.cbWndExtra = 0;            /* No per-window extra data.      */
  50.         wc.hInstance = hInstance;        /* Application that owns the class.      */
  51.         wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 
  52.         wc.lpszMenuName =   NULL;
  53.         wc.lpszClassName = "SampleWindClass"; /* Name used in call to CreateWindow. */
  54.         if (!RegisterClass(&wc)) return FALSE;
  55.  
  56.     };
  57.  
  58.     hWnd =CreateWindow("SampleWindClass","Sample"
  59.         ,WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW|WS_VISIBLE,
  60.         10,10,300,200,HWND_DESKTOP,0,hInstance,0);
  61.  
  62.  
  63.     while (hWnd && GetMessage(&msg,       /* message structure                 */
  64.         NULL,           /* handle of window receiving the message */
  65.         NULL,           /* lowest message to examine             */
  66.         NULL))           /* highest message to examine         */
  67.     {
  68.             TranslateMessage(&msg);       /* Translates virtual key codes         */
  69.             DispatchMessage(&msg);       /* Dispatches message to window         */
  70.     }
  71.     return (msg.wParam);       /* Returns the value from PostQuitMessage */
  72. }
  73.  
  74.  
  75. ///////////////////////////////////////////////////////////////////////////////////
  76. // Window handling code
  77.  
  78.  
  79. // set the values given a Flute array in dhand
  80. // hWnd - is the handle of the window
  81. HGLOBAL SetValues(HGLOBAL dhand, HWND hWnd )
  82. {
  83.     DataObj    *pob;
  84.     BOOL    b1,b2;
  85.  
  86.     if (!dhand) return 0;        // there is a problem (low mem?)
  87.     
  88.     pob = DataGlobalLock(dhand);
  89.     if (pob->tint.vtype!=ARRAYTYPE || pob->tarray.elements!=2) {
  90.         // we haven't been given the correct parameters - report an error
  91.         GlobalUnlock((HGLOBAL)dhand);
  92.         return (LRESULT) 
  93.             GeneralError(hInst,IDS_PARAMETERERROR);
  94.     };
  95.     
  96.     pob = PtrContent(pob);
  97.     lValue = GetALong(pob,&b1);
  98.     pob = NextDataObj(pob);
  99.     GetAString(pob, &b2, sValue,sizeof(sValue));
  100.     GlobalUnlock((HGLOBAL)dhand);
  101.     
  102.     // if the extraction of data failed, then report an error
  103.     if (!b1 || !b2)
  104.         return (LRESULT)
  105.             GeneralError(hInst,IDS_PARAMETERERROR);
  106.     
  107.     InvalidateRect(hWnd, NULL,FALSE);
  108.     return NULL;
  109. }
  110.  
  111. LRESULT GetValues()
  112. {
  113.     return (LRESULT)MakeArray2(MakeInt(lValue), MakeString(sValue) );
  114. }
  115.  
  116.  
  117.  
  118. /* text edit window handler procedure, used to edit text for program objects */
  119. long FAR PASCAL __export SampActWindProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  120. {
  121.     static    UINT    Acts[2];
  122.  
  123.     switch (message) {
  124.         case WM_CREATE:
  125.             strcpy(sValue,"Sample Text");
  126.             lValue =1000;
  127.             RegisterActList(hInst, IDS_ACTSTRING1,Acts);        // WINDACTS
  128.             SetWindowFluteName(hWnd, "My_Sample_Window");        // WINDACTS - name our window
  129.             break;
  130.         case WM_CLOSE:
  131.             PostQuitMessage(0);
  132.             break;
  133.         case WM_PAINT:
  134.             {
  135.                 // paint the window
  136.                 HDC    devcon;
  137.                 PAINTSTRUCT    ps;
  138.                 char    cbuffer[280];
  139.                 RECT    cr;
  140.  
  141.                 devcon=BeginPaint(hWnd,&ps);
  142.                 if (!devcon) break;
  143.                 sprintf(cbuffer,"%ld\r\n%s",lValue,sValue);
  144.                 GetClientRect(hWnd,&cr);
  145.                 DrawText(devcon,cbuffer,-1,&cr,DT_LEFT|DT_NOPREFIX|DT_EXPANDTABS);
  146.                 EndPaint(hWnd,&ps);
  147.  
  148.             };
  149.             break;
  150.         default:
  151.             // WINDACTS - code to process window acts
  152.             if (message == uActListMsg) {
  153.                 // a browser message has been received
  154.                 if (wParam) {
  155.                     // help on a function
  156.                     char    actname[128];
  157.                     FindActName(hInst, (UINT)wParam, IDS_ACTSTRING1, actname, sizeof(actname));
  158.                     WinHelp(hWnd,"SampAct.hlp",HELP_PARTIALKEY, (DWORD)actname);
  159.                     return NULL;
  160.                 } else {
  161.                     // return a list of functions
  162.                     return (LRESULT)ProduceActList(hInst, IDS_ACTSTRING1);
  163.                 };
  164.                 
  165.             } else if (message == Acts[0]) {
  166.                 // Set the values 
  167.                 return SetValues( (HGLOBAL) wParam, hWnd);
  168.             } else if (message == Acts[1]) {
  169.                 // Get the values
  170.                 return GetValues();
  171.             } else return DefWindowProc(hWnd,message,wParam,lParam);
  172.     };
  173.     return (NULL);
  174. }
  175.  
  176.  
  177.